﻿

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>项目管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <link href="../../../layuiadmin/jquery-editable-select/jquery-editable-select.css" rel="stylesheet" />
    <script src="../../../layuiadmin/lib/jquery.min.js"></script>
    <script src="../../../layuiadmin/lib/api.js"></script>
    <script src="../../../layuiadmin/artdialog/artDialog.js?skins=chrome"></script>
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../layuiadmin/lib/common.js"></script>
    <script src="../../../layuiadmin/lib/system.js"></script>
    <!--带输入和搜索的下拉框-->

    
    <script>
        //检查服务器是否已登录，没有登录则跳转至登录页。
        sys_islogin();
    </script>

</head>
<body>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
          <div class="layui-form-item">

              <div class="layui-inline">
                  <label class="layui-form-label">项目负责人</label>
                  <div class="layui-input-inline">
                      <!--<input type="text" name="leadername" placeholder="请输入" autocomplete="off" class="layui-input">-->
                      <select id="leadername" name="leadername" class="layui-select" style="width:190px;" data-placeholder="请输入">
                      </select>
                  </div>
              </div>
              <div class="layui-inline">
                  <label class="layui-form-label">项目成员</label>
                  <div class="layui-input-inline">
                      <!--<input type="text" name="membername" placeholder="请输入" autocomplete="off" class="layui-input">-->
                      <select id="membername" name="membername" class="layui-select" style="width:190px;" data-placeholder="请输入">
                      </select>
                  </div>
              </div>
              <div class="layui-inline">
                  <label class="layui-form-label">项目名</label>
                  <div class="layui-input-inline">
                      <input type="text" name="projectname" placeholder="请输入" autocomplete="off" class="layui-input">
                  </div>
              </div>
              <div class="layui-inline">
                  <label class="layui-form-label">选择日期</label>
                  <div class="layui-input-inline">
                      <input type="text" class="layui-input" name="startTime" id="startTime" autocomplete="off" placeholder="开始日期">
                  </div>
                  <div class="layui-form-mid">
                      -
                  </div>
                  <div class="layui-input-inline">
                      <input type="text" class="layui-input" name="endTime" id="endTime" autocomplete="off" placeholder="结束日期">
                  </div>
              </div>
              <div class="layui-inline">
                  <button class="layui-btn layuiadmin-btn-list" id="LAY-app-contlist-search" lay-submit lay-filter="LAY-app-contlist-search">
                      <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                  </button>
              </div>
          </div>
      </div>

      <div class="layui-card-body">
          <div style="padding-bottom: 10px;">
              <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
              <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
              <div class="layui-inline layui-form" style="margin-left:8px;width:120px !important;">
                  <select name="STATUS" id="STATUS" lay-filter="select_status" style="height:38px;">
                      
                  </select>
              </div>
              
          </div>
          
          <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>

          <script type="text/html" id="table-content-list">
              <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
              <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
          </script>
      </div>
    </div>
  </div>

  <script src="../../../layuiadmin/jquery-editable-select/jquery-editable-select.js"></script>
  <script>
      var statuslist = new Array();
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'contlist', 'table','laydate'], function(){
      var table = layui.table, form = layui.form;
    
    
    //监听搜索
    form.on('submit(LAY-app-contlist-search)', function(data){
        var field = data.field;
        console.log(data.field);
      //执行重载
      table.reload('LAY-app-content-list', {
        where: field
      });
    });

     
      //表格管理
      table.render({
          elem: '#LAY-app-content-list'
          , url: '/ProjectMerber/ProjectList' //接口
          , cols: [[
              { type: 'checkbox', fixed: 'left',field: 'ID' }              
              , { field: 'PROJECTNAME', title: '项目标题',align: 'center'}
              , { field: 'LEADERNAME', title: '负责人', align: 'center'}
              , { field: 'MEMBERNAME', title: '成员', align: 'center'}
              , {
                  field: 'STARTTIME', title: '开始时间', sort: true, align: 'center',
                  templet: function (d) {
                      return common.SubString(d.STARTTIME, 0, 10);
                  }
              }
              , {
                  field: 'ENDTIME', title: '结束时间', sort: true, align: 'center',
                  templet: function (d) {
                      return common.SubString(d.ENDTIME, 0, 10);
                  }
              }
              , { field: 'DAYS', title: '工作日', sort: true, align: 'center' }
              , {
                  field: 'STATUS', title: '项目状态', sort: true, align: 'center',
                  templet: function (d) {
                      var str = "";
                      for (var i = 0; i < statuslist.length; i++) {
                          if (statuslist[i].TYPE == 4 && statuslist[i].CODE == d.STATUS) {
                              str = statuslist[i].CODENAME;
                          }
                      }
                      return str;
                      
                  }
              }
          //, { field: 'UPDATETIME', title: '修改时间', sort: true, align: 'center' }
          //, { field: 'CREATETIME', title: '添加时间', sort: true, align: 'center' }
          , { title: '操作', minWidth: 180, align: 'center', fixed: 'right', toolbar: '#table-content-list' }
          ]]
          , page: true
          , limit: 10
          , where: {
              
          }
          , limits: [10, 15, 20, 25, 30]
          , text: {
              none: '暂无相关数据'
          }
      });

      //监听表格的操作栏
      table.on('tool(LAY-app-content-list)', function (obj) {
          var data = obj.data;
           
          if (obj.event === 'del') {
              layer.confirm('确定删除此项目吗？', function (index) {
                   
                  var isSucss = fun_del(data.ID);
                  if (isSucss>0) {
                      table.reload('LAY-app-content-list');
                      layer.msg('成功删除 ' + isSucss + " 数据");
                  }  
                  layer.close(index);
              });
          } else if (obj.event === 'edit') {
              layer.open({
                  type: 2
                  , title: '编辑项目'
                  , content: 'listform.html'
                  , maxmin: true
                  , area: ['960px', '680px']
                  , success: function (layero, index) {
                      var iframe = window['layui-layer-iframe' + index];
                      // 向子页面的全局函数child_select_user传参
                      iframe.child_fill_data(data);
                  }
                  
              });
          }
      });

    //表格上方的操作
    var $ = layui.$, active = {
        batchdel: function () {
            var checkStatus = table.checkStatus('LAY-app-content-list')
                , checkData = checkStatus.data; //得到选中的数据
            console.log(checkData);
            if (checkData.length === 0) {
                return layer.msg('请选择数据');
            }

            layer.confirm('确定删除项目吗？', function (index) {
                var ids = "";
                for (var i = 0; i < checkData.length; i++) {
                    ids += checkData[i].ID + ",";
                }
                var count = fun_del(ids);
                table.reload('LAY-app-content-list');
                layer.msg('成功删除 ' + count + " 数据");
             
        });
      },
      add: function(){
        layer.open({
          type: 2
          ,title: '添加项目'
          ,content: 'listform.html'
          ,maxmin: true
          ,area: ['960px', '680px']

        }); 
      }
      }; 

      //监听下拉框
      form.on('select(select_status)', function (data) {
          var checkStatus = table.checkStatus('LAY-app-content-list')
              , checkData = checkStatus.data; //得到选中的数据
          if (checkData.length === 0) {
              $("#STATUS option:first").prop("selected", 'selected');
              //$("#reset").click();
              return layer.msg('请选择需要修改状态的数据');
          }
          var ids = "";
          for (var i = 0; i < checkData.length; i++) {
              ids += checkData[i].ID + ",";
          }
          $.ajax({
              url: "/ProjectMerber/SetStatusById",    //请求的url地址
              dataType: "json",   //返回格式为json
              //async: false,//请求是否异步，默认为异步，这也是ajax重要特性$("#attachCode").val()
              data: { ids: ids, status: data.value },    //参数值
              type: "POST",   //请求方式
              success: function (res) {
                  if (res > 0) {
                      layer.msg("项目状态成功修改为：" + $("#STATUS option:selected").text());
                      table.reload('LAY-app-content-list');
                  }
                  else layer.msg(res.message);
              },
              error: function (res) {
                  console.log(res);
                  //layer.msg("任务附件获取失败，请联系技术人员");
              }
          });
      }); 

     
    $('.layui-btn.layuiadmin-btn-list').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

      //任务负责人搜索
      $("input[name=leadername]").blur(function () {
          $("#LAY-app-contlist-search").click();
      });
      //任务组员搜索
      $("input[name=membername]").blur(function () {
          $("#LAY-app-contlist-search").click();
      });

      var laydate = layui.laydate;
      //开始日期
      var insStart = laydate.render({
          elem: '#startTime'
          //, min: 0
          //, type: 'datetime'
          , done: function (value, date) {
              //更新结束日期的最小日期
              insEnd.config.min = lay.extend({}, date, {
                  month: date.month - 1
              });

              //自动弹出结束日期的选择器
              insEnd.config.elem[0].focus();
          }
      });

      //结束日期
      var insEnd = laydate.render({
          elem: '#endTime'
          //, min: 0
          //, type: 'datetime'
          , done: function (value, date) {
              //更新开始日期的最大日期
              insStart.config.max = lay.extend({}, date, {
                  month: date.month - 1
              });
          }
      });

  });

      function fun_del(ids) {
          var isSucc = 0;
          $.ajax({
              url: "/ProjectMerber/DeleteProject",    //请求的url地址
              dataType: "json",   //返回格式为json
              async: false,//请求是否异步，默认为异步，这也是ajax重要特性
              data: { delIds: ids },    //参数值
              type: "POST",   //请求方式
              beforeSend: function () {
                  //请求前的处理
              },
              success: function (data) {
                  //请求成功时处理
                  isSucc = data;                  
              },

              error: function (res) {
                  layer.msg("删除失败，请联系技术人员");
              }
          });
          return isSucc;
      };

      //获取项目状态
      $.ajax({
          url: "/ProjectMerber/ProjectDicListAll",    //请求的url地址
          dataType: "json",   //返回格式为json
          async: false,//请求是否异步，默认为异步，这也是ajax重要特性
          data: {},    //参数值
          type: "POST",   //请求方式
          success: function (data) {
              //请求成功时处理
              statuslist = data;
              var html = "<option title=\"\" value=\"\">项目状态</option>";
              for (var i = 0; i < data.length; i++) {
                  if (data[i].TYPE == 4) {
                      html += "<option title = \"" + data[i].CODENAME + "\" value = \"" + data[i].CODE + "\" >" + data[i].CODENAME + "</option >";   
                  }                                    
              }
              $("#STATUS").html(html);
          },

          error: function (res) {
              layer.msg("删除失败，请联系技术人员");
          }
      });

      //任务负责人
      $.ajax({
          url: "/UserMerber/GetUserByDepartId",    //请求的url地址
          dataType: "json",   //返回格式为json
          //async: false,//请求是否异步，默认为异步，这也是ajax重要特性$("#attachCode").val()
          data: {},    //参数值
          type: "POST",   //请求方式
          success: function (res) {
              var html = "";
              for (var i = 0; i < res.length; i++) {
                  html += "<option value='" + res[i].ID + "'>" + res[i].REALNAME + "</option>";
              }

              $("#leadername").html(html);
              $("#membername").html(html);
              $("#leadername").editableSelect();
              $("#membername").editableSelect();
          },
          error: function (res) {
              console.log(res);
              //layer.msg("任务附件获取失败，请联系技术人员");
          }
      });   
  </script>
</body>
</html>
